<template>
    <el-dialog :visible="visible" title="添加应用" width="420px" @close="visible = false">
        <el-form :model="form" label-width="90px" @keyup.enter="submit()">
            <el-form-item prop="name" label="应用名称">
                <el-input v-model="form.name" placeholder="应用名称"></el-input>
            </el-form-item>
            <el-form-item prop="description" label="应用介绍">
                <el-input v-model="form.description" placeholder="应用介绍"></el-input>
            </el-form-item>
            <el-form-item prop="category" label="应用分类">
                <el-input v-model="form.category" placeholder="应用分类"></el-input>
            </el-form-item>
            <el-form-item prop="recommend" label="推荐语">
                <el-input v-model="form.recommend" placeholder="推荐语"></el-input>
            </el-form-item>
            <el-form-item prop="icon" label="应用图标">
                <el-input v-model="form.icon" placeholder="应用图标"></el-input>
            </el-form-item>
            <el-form-item prop="star" label="评分">
                <el-input v-model="form.star" placeholder="评分"></el-input>
            </el-form-item>
            <el-form-item prop="size" label="应用大小">
                <el-input v-model="form.size" placeholder="应用大小"></el-input>
            </el-form-item>
            <el-form-item prop="version" label="应用版本">
                <el-input v-model="form.version" placeholder="应用版本"></el-input>
            </el-form-item>
            <el-form-item prop="developer" label="应用开发者">
                <el-input v-model="form.developer" placeholder="应用开发者"></el-input>
            </el-form-item>
        </el-form>
        <template #footer>
            <el-button @click="visible = false">取消</el-button>
            <el-button type="primary" @click="submit()">确定</el-button>
        </template>
    </el-dialog>
</template>

<script>
import { postSync } from '@/util/request'
let _this = null
export default {
    name: 'CreateApp',
    data() {
        return {
            visible: false,
            form: {
                name: '',
                description: '',
                category: '',
                recommend: '',
                icon: '',
                star: '',
                size: '',
                version: '',
                developer: ''
            }
        }
    },
    created() {
        _this = this
    },
    methods: {
        show: () => {
            _this.visible = true
        },
        submit: () => {
            _this.visible = false
            postSync('/api/app/create', {
                ..._this.form
            }).then((res) => {
                if (res.code == 200) {
                    _this.$notify({
                        title: '成功',
                        message: '创建成功',
                        duration: 3000,
                        type: 'success'
                    })
                    _this.$emit('load')
                    _this.form = {
                        name: '',
                        description: '',
                        category: '',
                        recommend: '',
                        icon: '',
                        star: '',
                        size: '',
                        version: '',
                        developer: ''
                    }
                }
            })
        }
    }
}
</script>

<style lang="scss" scoped>

</style>